package com.wm.action;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.wm.bean.Restaurant;
import com.wm.service.RestaurantService;
import com.wm.vo.RestaurantListVO;

import cn.itcast.service.PersonService;
import com.wm.vo.*;
public class RestaurantAction extends DispatchAction {
	@Resource RestaurantService restaurantService;

/*	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		System.out.println("execute");
		int page = 1;
		System.out.println(request.getParameter("page"));
		if (request.getParameter("page")!=null && !request.getParameter("page").equals("")) {
			page = Integer.parseInt(request.getParameter("page"));
		}
		System.out.println("page="+page);
		RestaurantListVO restaurantListVO = new RestaurantListVO();
		restaurantListVO.requestPage = page;
		
		request.setAttribute("restaurants", restaurantService.listRestaurants(restaurantListVO));
//		System.out.println(restaurantService.listRestaurants(restaurantListVO).requestPage);
		return mapping.findForward("listfd");
	}*/
	/**
	 * 获得当前校区所有饭店
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward getAllRest (ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
			throws Exception {/*
		WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(
				this.getServlet().getServletContext());
		PersonService personService =(PersonService)ctx.getBean("personService");*/
		System.out.println("------getallrestacton");
		int page = 1;
		System.out.println("请求第"+ request.getParameter("page")+"页");
		if (request.getParameter("page")!=null && !request.getParameter("page").equals("")) {
			page = Integer.parseInt(request.getParameter("page"));
		}
		RestaurantListVO restaurantListVO = new RestaurantListVO();
		restaurantListVO.requestPage = page;
		restaurantListVO.uid = request.getParameter("uid");
		
		request.setAttribute("restaurants", restaurantService.listRestaurants(restaurantListVO));
		//request.setAttribute("totalpages", restaurantListVO.getTotalPage());
		return mapping.findForward("listfd");
		
	} 
	
//	public ActionForward execute(ActionMapping mapping, ActionForm form,
//			HttpServletRequest request, HttpServletResponse response){
//		System.out.println("11111111111111111111111");
//		Restaurant res = new Restaurant();
//		res.setImgString("null");
//		res.setRid("hubei");
//		res.setIntroduction("meiyou jieshao");
//		res.setMobil("189........");
//		res.setPersonincharge("wo ");
//		res.setName("hubei");
//		res.setPhone("0451");
//		
//		restaurantService.addResturant(res);
//		
//		return mapping.findForward("addsuccess");
//	}

}
